package com.itboye.mengwu.data.presenter;

import java.util.List;
import java.util.Observer;

import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.object.BasePresenter;
import com.itboye.core.object.ResultEntity;
import com.itboye.mengwu.app.ui.main.MainPresenter;
import com.itboye.mengwu.data.interfaces.IBaby;
import com.itboye.mengwu.data.model.BabyBean;
import com.itboye.mengwu.data.repository.BabyRepository;

public class BabyPresenter extends BasePresenter implements IBaby<BabyBean> {
	public static final String BABYTIANJIANG_success = MainPresenter.class
			.getName() + "_BABYTIANJIANG_success";
	public static final String BABYTIANJIANG_fail = MainPresenter.class
			.getName() + "_BABYTIANJIANG_fail";

	public static final String BABYALL_success = MainPresenter.class.getName()
			+ "_BABYALL_success";
	public static final String BABYALL_fail = MainPresenter.class.getName()
			+ "_BABYALL_fail";

	public static final String BABYDETIAL_success = MainPresenter.class
			.getName() + "_BABYDETIAL_success";
	public static final String BABYDETIAL_fail = MainPresenter.class.getName()
			+ "_BABYDETIAL_fail";

	public static final String BABYXILIAN_success = MainPresenter.class
			.getName() + "_BABYXILIAN_success";
	public static final String BABYXILIAN_fail = MainPresenter.class.getName()
			+ "_BABYXILIAN_fail";

	public static final String BABYDELETE_success = MainPresenter.class
			.getName() + "_BABYDELETE_success";
	public static final String BABYDELETE_fail = MainPresenter.class.getName()
			+ "_BABYDELETE_fail";

	public BabyPresenter(Observer observer) {
		super(observer);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void add(BabyBean model) {
		// TODO Auto-generated method stub
		IBaby<BabyBean> iBaby = new BabyRepository(new ICompleteListener() {

			@Override
			public void success(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(BABYTIANJIANG_success);
				BabyPresenter.this.setChanged();
				BabyPresenter.this.notifyObservers(result);
			}

			@Override
			public void failure(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(BABYTIANJIANG_fail);
				BabyPresenter.this.setChanged();
				BabyPresenter.this.notifyObservers(result);
			}
		});
		iBaby.add(model);
	}

	@Override
	public void delete(BabyBean model) {
		// TODO Auto-generated method stub
		IBaby<BabyBean> iBaby = new BabyRepository(new ICompleteListener() {

			@Override
			public void success(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(BABYDELETE_success);
				BabyPresenter.this.setChanged();
				BabyPresenter.this.notifyObservers(result);
			}

			@Override
			public void failure(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(BABYDELETE_fail);
				BabyPresenter.this.setChanged();
				BabyPresenter.this.notifyObservers(result);
			}
		});
		iBaby.delete(model);
	}

	@Override
	public void update(BabyBean model) {
		// TODO Auto-generated method stub
		IBaby<BabyBean> iBaby = new BabyRepository(new ICompleteListener() {

			@Override
			public void success(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(BABYXILIAN_success);
				BabyPresenter.this.setChanged();
				BabyPresenter.this.notifyObservers(result);
			}

			@Override
			public void failure(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(BABYXILIAN_fail);
				BabyPresenter.this.setChanged();
				BabyPresenter.this.notifyObservers(result);
			}
		});
		iBaby.update(model);
	}

	@Override
	public void getInfo(BabyBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<BabyBean> queryYouHuiQuan(BabyBean model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void BabyAll(String uid) {
		// TODO Auto-generated method stub
		IBaby<BabyBean> iBaby = new BabyRepository(new ICompleteListener() {

			@Override
			public void success(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(BABYALL_success);
				BabyPresenter.this.setChanged();
				BabyPresenter.this.notifyObservers(result);
			}

			@Override
			public void failure(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(BABYALL_fail);
				BabyPresenter.this.setChanged();
				BabyPresenter.this.notifyObservers(result);
			}
		});
		iBaby.BabyAll(uid);
	}

	@Override
	public void BabyDetial(String uid, String id) {
		// TODO Auto-generated method stub
		IBaby<BabyBean> iBaby = new BabyRepository(new ICompleteListener() {

			@Override
			public void success(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(BABYDETIAL_success);
				BabyPresenter.this.setChanged();
				BabyPresenter.this.notifyObservers(result);
			}

			@Override
			public void failure(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(BABYDETIAL_fail);
				BabyPresenter.this.setChanged();
				BabyPresenter.this.notifyObservers(result);
			}
		});
		iBaby.BabyDetial(uid, id);
	}

}
